package com.workcell.workdata.xthings.service.factory;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.workcell.workdata.xthings.constant.HardwareTypeEnum;
import com.workcell.workdata.xthings.dto.CodeChainnumVo;
import com.workcell.workdata.xthings.service.impl.mqtt.*;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * @Author 廖博文
 * @Date 2022/12/5 14:35
 * @Description 硬件真实数据处理工厂
 */
@RequiredArgsConstructor
@Service
public class HardwareRealDataFactory {

	private final FlowMeterRealDataServiceImpl flowMeterRealDataService;
	private final PowerMeterRealDataServiceImpl powerMeterRealDataService;
	private final BeltScalesRealDataServiceImpl beltScalesMeterRealDataService;
	private final ValveRealDataServiceImpl valveRealDataService;
	private final LevelGaugeRealDataServiceImpl levelGaugeRealDataService;
	private final FreezerRealDataServiceImpl freezerRealDataService;
	private final HeatExchangersRealDataServiceImpl heatExchangersRealDataService;
	private final UpperComputerDataDataServiceImpl upperComputerDataService;
	private final SmartTanksRealDataServiceImpl smartTanksRealDataService;
	private final WaterMeterDataServiceImpl waterMeterDataService;

	/**
	 * 获取硬件最近的一次数据
	 * @param deviceNo 设备编号
	 * @param hardwareType 硬件类型
	 * @param time 最近时间
	 * @return
	 */
	public Object getLatelyDataInfo(String deviceNo, String hardwareType, String manufacturerCode, Integer time){
		switch (HardwareTypeEnum.getByCode(hardwareType)){
			case FLOW_METER :
				return flowMeterRealDataService.getLatelyDataInfo(deviceNo, manufacturerCode, time);
			case POWER_METER:
				return powerMeterRealDataService.getLatelyDataInfo(deviceNo, manufacturerCode, time);
			case BELT_SCALES:
				return beltScalesMeterRealDataService.getLatelyDataInfo(deviceNo, manufacturerCode, time);
			case FREEZER:
				return freezerRealDataService.getLatelyDataInfo(deviceNo, manufacturerCode, time);
			case HEAT_EXCHANGERS:
				return heatExchangersRealDataService.getLatelyDataInfo(deviceNo, manufacturerCode, time);
			case VALVE:
				return valveRealDataService.getLatelyDataInfo(deviceNo, manufacturerCode, time);
			case UPPER_COMPUTER:
				return upperComputerDataService.getLatelyDataInfo(deviceNo, manufacturerCode, time);
			case SMART_TANKS:
				return smartTanksRealDataService.getLatelyDataInfo(deviceNo, manufacturerCode, time);
			case WATER_METER:
				return waterMeterDataService.getLatelyDataInfo(deviceNo, manufacturerCode, time);
			default :
				return null;
		}
	}

	/**
	 * 获取硬件最近六个小时的数据：折线图
	 * @param deviceNo
	 * @return
	 */
	public Object getDataHourLineChartInfo(String deviceNo, String hardwareType, String manufacturerCode){
		switch (HardwareTypeEnum.getByCode(hardwareType)){
			case FLOW_METER :
				return flowMeterRealDataService.getDataHourLineChartInfo(deviceNo, manufacturerCode);
			case POWER_METER:
				return powerMeterRealDataService.getDataHourLineChartInfo(deviceNo, manufacturerCode);
			case BELT_SCALES:
				return beltScalesMeterRealDataService.getDataHourLineChartInfo(deviceNo, manufacturerCode);
			case VALVE:
				return valveRealDataService.getDataHourLineChartInfo(deviceNo, manufacturerCode);
			case UPPER_COMPUTER:
				return upperComputerDataService.getDataHourLineChartInfo(deviceNo, manufacturerCode);
			case SMART_TANKS:
				return smartTanksRealDataService.getDataHourLineChartInfo(deviceNo, manufacturerCode);
			case WATER_METER:
				return waterMeterDataService.getDataHourLineChartInfo(deviceNo, manufacturerCode);
			default :
				return null;
		}
	}

	/**
	 * 硬件设备数据采集
	 * @param selectChainNumDataVo
	 * @return
	 */
	public Page getHardwareDataInfo(CodeChainnumVo.SelectChainNumDataVo selectChainNumDataVo) {
		switch (HardwareTypeEnum.getByCode(selectChainNumDataVo.getHardwareType())){
			case POWER_METER:
				return powerMeterRealDataService.getHardwareDataInfo(selectChainNumDataVo);
			case FLOW_METER:
				return flowMeterRealDataService.getHardwareDataInfo(selectChainNumDataVo);
			case FREEZER:
				return freezerRealDataService.getHardwareDataInfo(selectChainNumDataVo);
			case HEAT_EXCHANGERS:
				return heatExchangersRealDataService.getHardwareDataInfo(selectChainNumDataVo);
			case LEVEL_GAUGE:
				return levelGaugeRealDataService.getHardwareDataInfo(selectChainNumDataVo);
			case VALVE:
				return valveRealDataService.getHardwareDataInfo(selectChainNumDataVo);
			case UPPER_COMPUTER:
				return upperComputerDataService.getHardwareDataInfo(selectChainNumDataVo);
			case SMART_TANKS:
				return smartTanksRealDataService.getHardwareDataInfo(selectChainNumDataVo);
			default :
				return null;
		}
	}

	public Object getRealData(String deviceNo, String hardwareType) {
		switch (HardwareTypeEnum.getByCode(hardwareType)) {
			case FREEZER:
				return freezerRealDataService.getRealData(deviceNo);
			case HEAT_EXCHANGERS:
				return heatExchangersRealDataService.getRealData(deviceNo);
			case VALVE:
				return valveRealDataService.getRealData(deviceNo);
			case UPPER_COMPUTER:
				return upperComputerDataService.getRealData(deviceNo);
			case SMART_TANKS:
				return smartTanksRealDataService.getRealData(deviceNo);
			default:
				return null;
		}
	}
}
